package com.hok.misc.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URLConnection;

public class ProxyURL {
	public static void main(String[] args) throws IOException {
		System.setProperty("http.proxyHost", "hzproxy.asiainfo-linkage.com");
		System.setProperty("http.proxyPort", "8080");
		System.getProperties().put( "proxySet", "true" );
		
		SocketAddress addr = new InetSocketAddress("hzproxy.asiainfo-linkage.com", 8080);
		Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
		URL url = new URL("http://www.baidu.com");
		
		Authenticator.setDefault(new HttpAuthenticateProxy());
		URLConnection con = url.openConnection();
		BufferedReader in = new BufferedReader(new InputStreamReader(
				con.getInputStream()));
		String inputLine;
		while ((inputLine = in.readLine()) != null)
			//new String(inputLine.getBytes("big5"), "utf-8")
			System.out.println(new String(inputLine.getBytes(), "gbk"));
		in.close();
	}
}

class HttpAuthenticateProxy extends Authenticator {

	protected PasswordAuthentication getPasswordAuthentication() {
		// username, password
		// sets http authentication
		return new PasswordAuthentication("ailk\\zhanght3", "hiHI58%*".toCharArray());
	};

}